//
//  YWUIActionSheet.m
//  YWBaseFrameWork
//
//  Created by mac on 16/7/17.
//  Copyright © 2016年 NeiQuan. All rights reserved.
//

#import "YWUIActionSheet.h"
#include <objc/runtime.h>
@interface YWUIActionSheet ()<UIActionSheetDelegate>


@end
static const void *YWActionKey = &YWActionKey;
@implementation YWUIActionSheet

- (instancetype)initWithTitle:( NSString *)title  cancelButtonTitle:( NSString *)cancelButtonTitle destructiveButtonTitle:( NSString *)destructiveButtonTitle clickindex:(YWactionblock)block otherButtonTitles:( NSString *)otherButtonTitles, ... {
    
    if (self=[ super initWithTitle:title delegate:self cancelButtonTitle:cancelButtonTitle destructiveButtonTitle:destructiveButtonTitle otherButtonTitles:otherButtonTitles,nil ])
    {
        objc_setAssociatedObject(self, YWActionKey, block, OBJC_ASSOCIATION_COPY);
        
        unsigned int count = 0;
        Ivar *ivars = class_copyIvarList([ self class], &count);//获取成员变量列表
        
        
        for (int i = 0 ; i < count; i++)
        {
            Ivar ivar = ivars[i];
            // 属性名称
            NSString *ivarName = [NSString stringWithUTF8String:ivar_getName(ivar)];
            NSLog(@"property---->%@", ivarName);
       }
        
        
        //获取属性列表
        objc_property_t *propertyList = class_copyPropertyList([UIImage class], &count);
        for (unsigned int i=0; i<count; i++) {
            const char *propertyName = property_getName(propertyList[i]);
            NSLog(@"property---->%@", [NSString stringWithUTF8String:propertyName]);
        }
        
    }
    
    return self;
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    YWactionblock  block=  objc_getAssociatedObject(self, YWActionKey);
    
     block(buttonIndex);
    
}
@end
